package mi.payment.admin.pay88;

import java.io.Serializable;
import java.util.HashMap;

import mi.payment.MyApplication;
import mi.payment.R;
import mi.payment.utils.SharedPreferencesUtil;

public class IPay88Operation {

    private static final String KEY_MERCHANT = "key_iPay88_merchant";
    private static final String KEY_WALLET = "key_iPay88_wallet";

    private static IPay88Operation instance;

    public static IPay88Operation getInstance() {
        if (instance == null) {
            instance = new IPay88Operation();
        }
        return instance;
    }

    public void saveIPay88Bean(IPay88Bean bean) {
        SharedPreferencesUtil.saveObj(bean, KEY_MERCHANT);
    }

    public IPay88Bean getIPay88Bean() {
        Serializable obj = SharedPreferencesUtil.readObj(KEY_MERCHANT);
        if (obj instanceof IPay88Bean) {
            return (IPay88Bean) obj;
        }
        return new IPay88Bean();
    }

    public void saveIPay88Wallet(IPay88Wallet wallet) {
        if (wallet == null) return;
        HashMap<String, IPay88Wallet> map = getIPay88WalletMap();
        map.put(wallet.name, wallet);
        saveIPay88WalletMap(map);
    }

    public void saveIPay88WalletMap(HashMap<String, IPay88Wallet> map) {
        SharedPreferencesUtil.saveObj(map, KEY_WALLET);
    }

    public IPay88Wallet getIPay88Wallet(String key) {
        HashMap<String, IPay88Wallet> map = getIPay88WalletMap();
        return map.get(key);
    }

    public HashMap<String, IPay88Wallet> getIPay88WalletMap() {
        Serializable obj = SharedPreferencesUtil.readObj(KEY_WALLET);
        HashMap<String, IPay88Wallet> map = null;
        if (obj instanceof HashMap) {
            map = ( HashMap<String, IPay88Wallet> ) obj;
        }
        if (map == null || map.size() == 0) {
            map = initWalletMap();
        }
        return map;
    }

    private HashMap<String, IPay88Wallet> initWalletMap() {
        HashMap<String, IPay88Wallet> map = new HashMap<>();

        IPay88Wallet wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_ali);
        wallet.iconResId = R.drawable.pay_ali;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "234";
        wallet.userSwitch = true;
        wallet.userPaymentID = "233";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_boost);
        wallet.iconResId = R.drawable.pay_boost;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "320";
        wallet.userSwitch = true;
        wallet.userPaymentID = "327";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_wx_myr);
        wallet.iconResId = R.drawable.pay_wx_myr;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "343";
        wallet.userSwitch = true;
        wallet.userPaymentID = "344";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_cim);
        wallet.iconResId = R.drawable.pay_cim;
        wallet.userSwitch = true;
        wallet.userPaymentID = "346";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_m_cash);
        wallet.iconResId = R.drawable.pay_m_cash;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "329";
        wallet.userSwitch = true;
        wallet.userPaymentID = "328";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_wx_cny);
        wallet.iconResId = R.drawable.pay_wx_cny;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "296";
        wallet.userSwitch = true;
        wallet.userPaymentID = "308";
        wallet.currency = "CNY";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_grab);
        wallet.iconResId = R.drawable.pay_grab;
        wallet.userSwitch = true;
        wallet.userPaymentID = "347";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_may_bank);
        wallet.iconResId = R.drawable.pay_may_bank;
        wallet.userSwitch = true;
        wallet.userPaymentID = "345";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_nets);
        wallet.iconResId = R.drawable.pay_nets;
        wallet.userSwitch = true;
        wallet.userPaymentID = "348";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_touch);
        wallet.iconResId = R.drawable.pay_touch_go;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "336";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_union);
        wallet.iconResId = R.drawable.pay_union;
        wallet.merchantSwitch = true;
        wallet.merchantPaymentID = "338";
        wallet.userSwitch = true;
        wallet.userPaymentID = "339";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        wallet = new IPay88Wallet();
        wallet.name = getString(R.string.pay88_setting_v_cash);
        wallet.iconResId = R.drawable.pay_v_cash;
        wallet.userSwitch = true;
        wallet.userPaymentID = "291";
        wallet.currency = "MYR";
        map.put(wallet.name, wallet);

        return map;
    }

    private String getString(int resId) {
        return MyApplication.context.getString(resId);
    }


}
